#include <iostream>
#include <stack>
using namespace std;

template<class T>
void Conversion(stack<T>& S, int data, int format) {
    // 15 = 'F' - 'A' + 10
    // ch = 'A' + num - 10
    while (data) {
        S.push(data % format);
        data /= format;
    }
    while (S.size()) {
        int num = S.top();
        if (num < 10) cout << num;
        else cout << (char)('A' + num - 10);
        S.pop();
    }
}

int main() {
    stack<int> s;
    int data, format;
    cin >> data >> format;
    Conversion(s, data, format);
    return 0;
}